package com.download.database;

import android.arch.persistence.room.ColumnInfo;
import android.arch.persistence.room.Embedded;
import android.arch.persistence.room.Entity;
import android.arch.persistence.room.Ignore;
import android.arch.persistence.room.PrimaryKey;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

/**
 * Created by chensuilun on 2019/3/13.
 */
@Entity(tableName = "ts_tasks")
public class TsTask {

    @PrimaryKey
    @ColumnInfo(name = "downloadId")
    private long mId;

    @ColumnInfo(name = "parentId", index = true)
    private long mParentId;

    @ColumnInfo(name = "seg_index")
    private int mIndex;

    @NonNull
    @ColumnInfo(name = "url")
    private String mUrl;

    @NonNull
    @ColumnInfo(name = "targetPath")
    private String mTargetPath;

    @ColumnInfo(name = "so_far")
    private long mCurDuration;

    @ColumnInfo(name = "total_duration")
    private long mDuration;

    @Embedded
    @Nullable
    private TsKey mTsKey;


    @Ignore
    public TsTask(long id, long parentId, int index, @NonNull String url, @NonNull String targetPath, long duration) {
        this(id, parentId, index, url, targetPath, 0, duration, null);
    }

    @Ignore
    public TsTask(long id, long parentId, int index, @NonNull String url, @NonNull String targetPath, long duration, @Nullable TsKey tsKey) {
        this(id, parentId, index, url, targetPath, 0, duration, tsKey);
    }

    public TsTask(long id, long parentId, int index, @NonNull String url, @NonNull String targetPath, long curDuration, long duration, @Nullable TsKey tsKey) {
        mId = id;
        mParentId = parentId;
        mIndex = index;
        mUrl = url;
        mTargetPath = targetPath;
        mCurDuration = curDuration;
        mDuration = duration;
        mTsKey = tsKey;
    }

    public int getIndex() {
        return mIndex;
    }

    public long getId() {
        return mId;
    }

    public void setCurDuration(long curDuration) {
        mCurDuration = curDuration;
    }


    public long getParentId() {
        return mParentId;
    }

    @NonNull
    public String getUrl() {
        return mUrl;
    }

    @NonNull
    public String getTargetPath() {
        return mTargetPath;
    }

    public long getCurDuration() {
        return mCurDuration;
    }

    public long getDuration() {
        return mDuration;
    }

    @Nullable
    public TsKey getTsKey() {
        return mTsKey;
    }

    @Override
    public String toString() {
        return "TsTask{" +
                "mId=" + mId +
                ", mParentId=" + mParentId +
                ", mIndex=" + mIndex +
                ", mUrl='" + mUrl + '\'' +
                ", mTargetPath='" + mTargetPath + '\'' +
                ", mCurDuration=" + mCurDuration +
                ", mDuration=" + mDuration +
                ", mEncrypted=" + (mTsKey != null) +
                '}';
    }
}
